import requests

payload = {}
headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Referer': 'https://www.kuaidi100.com/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
    'sec-ch-ua': '"Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"',
    'Cookie': 'csrftoken=V30d_raeHdErrDdYTxbCB8jJaM5RH04a3SpZVc5TUSU; _adadqeqwe1321312dasddocTitle=kuaidi100; _adadqeqwe1321312dasddocReferrer=; _adadqeqwe1321312dasddocHref=; Hm_lvt_22ea01af58ba2be0fec7c11b25e88e6c=1762140434; _ga=GA1.1.979153842.1762140437; _gcl_au=1.1.1049485945.1762140437; _ga_RX03B5S2PX=GS2.1.s1762140437$o1$g0$t1762140438$j59$l0$h0; WWWID=WWWEC4FEF1C6A756B3725439A3CFE62E717; Hm_lpvt_22ea01af58ba2be0fec7c11b25e88e6c=1762140761; HMACCOUNT=8D4FBA72F54F5323; snt_query_meta=%7B%22date%22%3A%222025103%22%2C%22nums%22%3A%5B%22DPK301793368204%22%2C%22JT3140859740934%22%5D%7D; hide_snt_query_meta=2025103'
}


def get_sms_info(code: str, sms_code=None):
    """
    获取短信内容
    :param code: 快递单号
    :return:
    """
    if "DPK" in code:
        url = "https://www.kuaidi100.com/query?type=debangkuaidi&postid=" + code + "&temp=0.22246298399148057&phone="
    elif "JD" in code:
        url = "https://www.kuaidi100.com/query?type=jd&postid=" + code + "&temp=0.22246298399148057&phone="
    elif "SF" in code:
        url = "https://www.kuaidi100.com/query?type=shunfeng&postid=" + code + "&temp=0.22246298399148057&phone=" + str(sms_code)
    else:
        return {"message": "快递单号错误"}

    response = requests.request("GET", url, headers=headers, data=payload)

    return {"message": response.json()["data"][0]['ftime'] + " " + response.json()["data"][0]['context']}


if __name__ == '__main__':
    print(get_sms_info("SF1555978504506", 1821))
